package com.example.controller;

import com.example.model.WxbMemeber;
import com.example.model.WxbOrder;
import com.example.service.WxbOrderService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private WxbOrderService wxbOrderService;


    @RequestMapping("/creatOrder")
    public String creatOrder(WxbOrder wxbOrder, Model model){
        WxbMemeber wxbMemeber = (WxbMemeber) SecurityUtils.getSubject().getPrincipal();
        model.addAttribute("wxbMemeber",wxbMemeber);
        if(wxbOrderService.insertWxbOrder(wxbOrder)){
            //订单添加成功

            model.addAttribute("orders",wxbOrderService.findListByUserId(wxbMemeber.getMemeberId()));
            return "我的推广订单";
        }
        return "index";

    }
    @RequestMapping("/list")
    public String queryOrderList(Model model){
        WxbMemeber wxbMemeber = (WxbMemeber) SecurityUtils.getSubject().getPrincipal();
        model.addAttribute("wxbMemeber",wxbMemeber);
        model.addAttribute("orders",wxbOrderService.findListByUserId(wxbMemeber.getMemeberId()));
        return "我的推广订单";


    }
}
